home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / Online / x3270 / unix_files / Examples / peer_script.ksh < prev    next >
Encoding:
Text File  |  2008-08-17  |  2.1 KB  |  124 lines

  1. #! /bin/ksh
  2. # TSO login script, which runs as a peer of x3270.
  3. # ksh version
  4.  
  5. #set -x
  6. me=${0##*/}
  7.  
  8. # Set up login parameters
  9. tcp_host=${1-ibmsys}
  10. dial_user=${2-VTAM}
  11. sna_host=${3-TSO}
  12. userid=${4-USERID}
  13. password=${5-PASSWORD}
  14.  
  15. # Verbose flag for x3270if
  16. #v="-v"
  17.  
  18. # Define some handly local functions.
  19.  
  20. # x3270 interface function
  21. function xi
  22. {
  23.     X3270OUTPUT=6 X3270INPUT=5 x3270if 5>&p 6<&p $v "$@"
  24. }
  25.  
  26. # Common x3270 Ascii function
  27. function ascii
  28. {
  29.     xi 'Ascii('$1')'
  30. }
  31.  
  32. # Common x3270 String function
  33. function string
  34. {
  35.     xi 'String("'"$@"'")'
  36. }
  37.  
  38. # x3270 cursor column
  39. function cursor_col
  40. {
  41.     xi -s 10
  42. }
  43.  
  44. # x3270 connection status
  45. function cstatus
  46. {
  47.     xi -s 4
  48. }
  49.  
  50. # Failure.
  51. function die
  52. {
  53.     xi "Info(\"$me error: $@\")"
  54.     xi "CloseScript(1)"
  55.     exit 1
  56. }
  57.  
  58. # Start x3270 as a co-process
  59. x3270 -script -model 2 2>&1 |&
  60. xp=$!
  61. xi -s 0 >/dev/null || exit 1
  62.  
  63. # Connect to host
  64. xi "Connect($tcp_host)" || die "Connection failed."
  65.  
  66. # Make sure we're connected.
  67. xi Wait
  68. [ "$(cstatus)" = N ] && die "Not connected."
  69.  
  70. # Get to a VM command screen
  71. xi Enter
  72.  
  73. # Wait for VM's prompt
  74. while [ "$(ascii 1,0,5)" != "Enter" ]
  75. do    sleep 2
  76. done
  77.  
  78. # Dial out to VTAM
  79. string "DIAL $dial_user"
  80. xi Enter
  81. typeset -i sl=10+${#dial_user}
  82. typeset -i dl=5+${#dial_user}
  83. while [ "$(ascii 0,64,4)" != VTAM ]
  84. do    s="$(ascii 8,0,$sl | sed 's/^ *//')"
  85.     if [ "$s" != "DIALED TO $dial_user" -a "$s" != "" ]
  86.     then    if [ "$(ascii 7,0,$dl)" = "DIAL $dial_user" ]
  87.         then    die "Couldn't get to VTAM"
  88.         fi
  89.     fi
  90.     sleep 2
  91. done
  92.  
  93. # Get to the SNA host
  94. string "$sna_host $userid"
  95. xi Enter
  96.  
  97. # Pass VTAM digestion message and initial blank TSO screen
  98. while [ "$(ascii 0,21,20)" = "USS COMMAND HAS BEEN" ]
  99. do    sleep 2
  100. done
  101. while :
  102. do    s="$(ascii 0,33,11 | sed 's/^ *//')"
  103.     [ "$s" != "" ] && break
  104.     sleep 2
  105. done
  106.  
  107. # Now verify the "TSO/E LOGON" screen
  108. [ "$s" = "TSO/E LOGON" ] || die "Couldn't get to TSO logon screen"
  109.  
  110. # Pump in the password
  111. string "$password"
  112. xi Enter
  113.  
  114. # Now look for "LOGON IN PROGRESS"
  115. typeset -i nl=18+${#userid}
  116. [ "$(ascii 0,11,$nl)" = "$userid LOGON IN PROGRESS" ] || die "Couldn't log on"
  117.  
  118. # Make sure TSO is waiting for a '***' enter
  119. [ "$(cursor_col)" -eq 5 ] || die "Don't understand logon screen"
  120.  
  121. # Off to ISPF
  122. xi Enter
  123. xi 'CloseScript(0)'
  124.